<?php

/* @var $this \yii\web\View */

/* @var $content string */

use yii\helpers\Html;
use yii\helpers\Url;
use app\assets\AppAsset;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <link rel="shortcut icon" href="/favicon.ico">
    <meta property="og:title" content="TourPig"/>
    <meta property="og:type" content="website"/>
    <meta property="og:site_name" content="tuzhu.ddr666.com"/>
    <meta property="og:url" content="https://tuzhu.ddr666.com"/>
    <meta property="og:description" content="途猪，一个一边旅游一边购物的旅游APP"/>
    <meta property="og:image" content="/icon.png"/>
    <meta charset="UTF-8" name="apple-itunes-app" content="app-id=1437508483">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
    <?php if (isset($this->blocks['otherCss'])): ?>
        <?= $this->blocks['otherCss'] ?>
    <?php endif; ?>
</head>
<body>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
<script>
    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1,                 //月份
            "d+": this.getDate(),                    //日
            "h+": this.getHours(),                   //小时
            "m+": this.getMinutes(),                 //分
            "s+": this.getSeconds(),                 //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
</script>
<?= $this->render('/jstemplate/auth') ?>
<script>
    // 一般引入qs库都赋值为qs，不过浏览器全局引入的是 window.Qs对象，
    // 所以直接用 qs.stringify() 会报 qs undefined
    var $admin = null;
    var total_refresh_token = false;

    var qs = Qs
    var http = axios.create({
        baseURL: '/xiaofengadminapi',
        timeout: 5000
    });
    http.param = (data = {}, contentType = 'application/x-www-form-urlencoded') => {
        return contentType === 'application/x-www-form-urlencoded' ? qs.stringify(data) : (contentType === 'application/json' ? JSON.stringify(data) : data);
    }
    //http拦截器
    http.interceptors.request.use(config => {
        const auth = getAuth();
        if (auth != null) {
            config.headers['Authorization'] = 'Bearer ' + auth.access_token;
            total_refresh_token = false;
        }
        return config;
    }, error => {

        return Promise.reject(error);
    })

    // 添加响应拦截器
    http.interceptors.response.use(function (response) {
        // 对响应数据做点什么
        return response;
    }, function (error) {
        // 对响应错误做点什么
        let response = error.response

        if (response.status === 401) {
            window.location.href = "<?=Url::to(['site/login'])?>";
        } else if (response.status === 403) {
            window.location.href = "<?=Url::to(['site/login'])?>";
        }
        return Promise.reject(error);
    });
    // 配置post的请求头
    axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

    var mycolors = {
        primary: '#457B9D',
        primaryVariant: '#1D3557',
        secondary: '#A8DADC',
        secondaryVariant: '#F1FAEE',
        background: 'white',
        surface: '#FFFFFF',
        error: 'red',
        accent: '#E63946',
        textOnPrimary: 'white',
        textOnSecondary: 'white',
        textOnBackground: '#263238',
        textOnSurface: '#263238',
        textOnError: 'white',
        textOnAccent: 'white'
    };

    var vuetify = new Vuetify({
        theme: {
            themes: {
                light: {
                    primary: mycolors.primary, // #E53935
                    secondary: mycolors.secondary, // #FFCDD2
                    accent: mycolors.accent, // #3F51B5
                },
                dark: {
                    primary: mycolors.primary, // #E53935
                    secondary: mycolors.secondary, // #FFCDD2
                    accent: mycolors.accent, // #3F51B5
                },
            },
            dark: false
        },
        icons: {
            //iconfont: 'fa',
        },
        lang: {
            current: 'zhHans',
        },
    });

    Vue.prototype.$colors = mycolors;

    var $lang_data = {};

    Vue.prototype.$lang = function (key) {
        return $lang_data.hasOwnProperty(key) ? $lang_data[key] : key;
    };

    Vue.prototype.$base_upload_url = function (url) {
        return "<?=Url::to('@base_upload')?>/" + url;
    }

    Vue.prototype.$upload_url = function (url) {
        return "<?=Url::to('@upload')?>/" + url;
    }


</script>
<?php if (isset($this->blocks['otherJs'])): ?>
    <?= $this->blocks['otherJs'] ?>
<?php endif; ?>
</body>
</html>
<?php $this->endPage() ?>
